﻿using BlazorAdmin.Models;
using BootstrapBlazor.Components;
using System.ComponentModel;

namespace BlazorAdmin.Web.Shared.Models
{
    public class DBLogSearchModel : ITableSearchModel
    {
        /// <summary>
        /// 
        /// </summary>
        [DisplayName("起止时间")]
        public DateTimeRangeValue? LogTime { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [DisplayName("脚本类型")]
        public string? Action { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public DBLogSearchModel()
        {
            Reset();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IEnumerable<IFilterAction> GetSearches()
        {
            var ret = new List<IFilterAction>();

            if (!string.IsNullOrEmpty(Action))
            {
                ret.Add(new SearchFilterAction(nameof(DBLog.Action), Action));
            }

            if (LogTime != null)
            {
                ret.Add(new SearchFilterAction(nameof(DBLog.LogTime), LogTime.Start, FilterAction.GreaterThanOrEqual));
                ret.Add(new SearchFilterAction(nameof(DBLog.LogTime), LogTime.End, FilterAction.LessThanOrEqual));
            }

            return ret;
        }

        /// <summary>
        /// 
        /// </summary>
        public void Reset()
        {
            LogTime = null;
            Action = null;
        }
    }
}
